package com.jb.workflow.app.bean;

import org.json.JSONException;
import org.json.JSONObject;

import net.oschina.app.bean.Entity;

public class FormData {
	
	//任务类型
	private String id;
	private String name;
	private String type;
	private String value;
	private boolean readable;
	private boolean writable;
	private boolean required;
	private String datePattern;
	private JSONObject dataObj;
	
	public JSONObject getDataObj() {
		return dataObj;
	}
	public void setDataObj(JSONObject dataObj) {
		this.dataObj = dataObj;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public boolean isReadable() {
		return readable;
	}
	public void setReadable(boolean readable) {
		this.readable = readable;
	}
	public boolean isWritable() {
		return writable;
	}
	public void setWritable(boolean writable) {
		this.writable = writable;
	}
	public boolean isRequired() {
		return required;
	}
	public void setRequired(boolean required) {
		this.required = required;
	}
	public String getDatePattern() {
		return datePattern;
	}
	public void setDatePattern(String datePattern) {
		this.datePattern = datePattern;
	}
	
	public static FormData parse(JSONObject obj) throws JSONException {
		FormData formData = new FormData();
		formData.setDataObj(obj);
		formData.setId(obj.getString("id"));
		formData.setName(obj.getString("name"));
		formData.setValue(obj.getString("value"));
		formData.setReadable(obj.getBoolean("readable"));
		formData.setRequired(obj.getBoolean("required"));
		formData.setWritable(obj.getBoolean("writable"));
		formData.setType(obj.getString("type"));
		if (obj.isNull("dataPattern")) {
			formData.setDatePattern(obj.getString("datePattern"));
		}
		
		return formData;
	}
}
